home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / bsd / ufs / inode.h < prev    next >
C/C++ Source or Header  |  1995-02-14  |  11KB  |  371 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software License Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  */
  7. /* 
  8.  * HISTORY
  9.  * 21-Feb-90  Morris Meyer (mmeyer) at NeXT
  10.  *    Backed out NFS 4.0 IMARK() macro.
  11.  *
  12.  * 28-Sep-89  Morris Meyer (mmeyer) at NeXT
  13.  *      NFS 4.0 Changes.
  14.  *
  15.  * 20-Sep-88  Avadis Tevanian (avie) at NeXT
  16.  *    Support fast symbolic links for NeXT too.
  17.  *
  18.  * 18-Nov-87  Avadis Tevanian (avie) at Carnegie-Mellon University
  19.  *    Eliminate MACH_VM conditional.
  20.  *
  21.  * 27-Oct-87  Peter King (king) at NeXT
  22.  *    SUN_VFS: Added NFS support.
  23.  *
  24.  * 25-May-87  Avadis Tevanian (avie) at Carnegie-Mellon University
  25.  *    Use vm_info field regardless of which options are enabled.
  26.  *
  27.  * 22-Jan-87  Michael Young (mwyoung) at Carnegie-Mellon University
  28.  *    MACH_XP: Correct type for inode.pager field.
  29.  *
  30.  * 22-Dec-86  David L. Black (dlb) at Carnegie-Mellon University
  31.  *    MULTIMAX: support Encore's fast symbolic links.
  32.  *
  33.  * 21-Oct-86  Jonathan J. Chew at Carnegie-Mellon University
  34.  *    Use romp definition of "i_size" and "di_size" fields in inode
  35.  *    structure with 68000.
  36.  *
  37.  * 14-Oct-86  Avadis Tevanian (avie) at Carnegie-Mellon University
  38.  *    Added changes for ns32000 byte ordering (from dlb).
  39.  *
  40.  * 31-May-86  Avadis Tevanian (avie) at Carnegie-Mellon University
  41.  *    Set the pager_id field in the inode structure.  This is a back
  42.  *    pointer to the real pager id which will allow for pager id's to
  43.  *    be different than inode numbers.
  44.  *
  45.  * 25-Jan-86  Avadis Tevanian (avie) at Carnegie-Mellon University
  46.  *    Upgraded to 4.3.
  47.  *
  48.  * 18-Feb-86  Bill Bolosky (bolosky) at Carnegie-Mellon University
  49.  *    Added different definitions of i_size and di_size for Sailboat
  50.  *    from IBM code under switch ROMP.  These differences are
  51.  *    presumably because of byte ordering differences.
  52.  */
  53.  
  54. /*
  55.  * Copyright (c) 1982, 1986 Regents of the University of California.
  56.  * All rights reserved.  The Berkeley software License Agreement
  57.  * specifies the terms and conditions for redistribution.
  58.  *
  59.  *    @(#)inode.h    7.1 (Berkeley) 6/4/86
  60.  */
  61.  
  62. /*    @(#)inode.h    2.2 88/06/20 4.0NFSSRC SMI;    from UCB 7.1 6/4/86    */
  63.  
  64. /*
  65.  * The I node is the focus of all local file activity in UNIX.
  66.  * There is a unique inode allocated for each active file,
  67.  * each current directory, each mounted-on file, text file, and the root.
  68.  * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
  69.  * Data in icommon is read in from permanent inode on volume.
  70.  */
  71.  
  72. #define    NDADDR    12        /* direct addresses in inode */
  73. #define    NIADDR    3        /* indirect addresses in inode */
  74. #if    defined(NeXT) || defined(MULTIMAX)
  75. #define MAX_FASTLINK_SIZE    ((NDADDR + NIADDR) * sizeof (daddr_t))
  76. #endif    defined(NeXT) || defined(MULTIMAX)
  77.  
  78. struct inode {
  79.     struct    inode *i_chain[2];    /* must be first */
  80.     struct    inode *inode_list;    /* list of all inodes --- could search
  81.                        inode hash table to traverse
  82.                        instead though */
  83.     struct    vnode i_vnode;    /* vnode associated with this inode */
  84.     struct    vnode *i_devvp;    /* vnode for block I/O */
  85.     u_short    i_flag;
  86.     dev_t    i_dev;        /* device where inode resides */
  87.     ino_t    i_number;    /* i number, 1-to-1 with device address */
  88.     off_t    i_diroff;    /* offset in dir, where we found last entry */
  89.     struct    fs *i_fs;    /* file sys associated with this inode */
  90.     struct    dquot *i_dquot;    /* quota structure controlling this file */
  91.     union {
  92.         daddr_t    if_lastr;    /* last read (read-ahead) */
  93.         struct    socket *is_socket;
  94.     } i_un;
  95.     struct    {
  96.         struct inode  *if_freef;    /* free list forward */
  97.         struct inode **if_freeb;    /* free list back */
  98.     } i_fr;
  99.     struct     icommon
  100.     {
  101.         u_short    ic_mode;    /*  0: mode and type of file */
  102.         short    ic_nlink;    /*  2: number of links to file */
  103.         uid_t    ic_uid;        /*  4: owner's user id */
  104.         gid_t    ic_gid;        /*  6: owner's group id */
  105.         quad    ic_size;    /*  8: number of bytes in file */
  106.         time_t    ic_atime;    /* 16: time last accessed */
  107.         long    ic_atspare;
  108.         time_t    ic_mtime;    /* 24: time last modified */
  109.         long    ic_mtspare;
  110.         time_t    ic_ctime;    /* 32: last time inode changed */
  111.         long    ic_ctspare;
  112. #if    defined(NeXT) || defined(MULTIMAX)
  113.         union {
  114.             struct { 
  115.             daddr_t    Mb_db[NDADDR]; /* 40: disk block addresses*/
  116.             daddr_t    Mb_ib[NIADDR]; /* 88: indirect blocks */
  117.             } ic_Mb;
  118. #define    ic_db    ic_Mun.ic_Mb.Mb_db
  119. #define    ic_ib    ic_Mun.ic_Mb.Mb_ib
  120.             char    ic_Msymlink[MAX_FASTLINK_SIZE];
  121.                         /* 40: symbolic link name */
  122.         } ic_Mun;
  123. #define ic_symlink    ic_Mun.ic_Msymlink
  124. #else    defined(NeXT) || defined(MULTIMAX)
  125.         daddr_t    ic_db[NDADDR];    /* 40: disk block addresses */
  126.         daddr_t    ic_ib[NIADDR];    /* 88: indirect blocks */
  127. #endif    defined(NeXT) || defined(MULTIMAX)
  128.         long    ic_flags;    /* 100: status, currently unused */
  129. #if    defined(NeXT) || defined(MULTIMAX)
  130. #define    IC_FASTLINK    0x0001        /* Symbolic link in inode */
  131. #endif    defined(NeXT) || defined(MULTIMAX)
  132.         long    ic_blocks;    /* 104: blocks actually held */
  133.         long    ic_gen;        /* 108: generation number */
  134.         long    ic_spare[4];    /* 112: reserved, currently unused */
  135.     } i_ic;
  136.     uid_t    i_ruid;            /* cached real uid for user mounts */
  137.     gid_t    i_rgid;            /* cached real gid for user mounts */
  138. };
  139.  
  140. struct dinode {
  141.     union {
  142.         struct    icommon di_icom;
  143.         char    di_size[128];
  144.     } di_un;
  145. };
  146.  
  147. #define    i_mode        i_ic.ic_mode
  148. #define    i_nlink        i_ic.ic_nlink
  149. #define    i_uid        i_ic.ic_uid
  150. #define    i_gid        i_ic.ic_gid
  151. /* ugh! -- must be fixed */
  152. #if    __LITTLE_ENDIAN__
  153. #define    i_size        i_ic.ic_size.val[0]
  154. #endif    __LITTLE_ENDIAN__
  155. #if    __BIG_ENDIAN__
  156. #define i_size        i_ic.ic_size.val[1]
  157. #endif    __BIG_ENDIAN__
  158. #define    i_db        i_ic.ic_db
  159. #define    i_ib        i_ic.ic_ib
  160. #if    defined(NeXT) || defined(MULTIMAX)
  161. #define    i_symlink    i_ic.ic_symlink
  162. #define i_icflags    i_ic.ic_flags
  163. #endif    defined(NeXT) || defined(MULTIMAX)
  164. #define    i_atime        i_ic.ic_atime
  165. #define    i_mtime        i_ic.ic_mtime
  166. #define    i_ctime        i_ic.ic_ctime
  167. #define i_blocks    i_ic.ic_blocks
  168. #define    i_rdev        i_ic.ic_db[0]
  169. #define    i_gen        i_ic.ic_gen
  170. #define    i_lastr        i_un.if_lastr
  171. #define    i_socket    i_un.is_socket
  172. #define    i_forw        i_chain[0]
  173. #define    i_back        i_chain[1]
  174. #define    i_freef        i_fr.if_freef
  175. #define    i_freeb        i_fr.if_freeb
  176.  
  177. #define di_ic        di_un.di_icom
  178. #define    di_mode        di_ic.ic_mode
  179. #define    di_nlink    di_ic.ic_nlink
  180. #define    di_uid        di_ic.ic_uid
  181. #define    di_gid        di_ic.ic_gid
  182. #if    __LITTLE_ENDIAN__
  183. #define    di_size        di_ic.ic_size.val[0]
  184. #endif    __LITTLE_ENDIAN__
  185. #if    __BIG_ENDIAN__
  186. #define di_size        di_ic.ic_size.val[1]
  187. #endif    __BIG_ENDIAN__
  188. #define    di_db        di_ic.ic_db
  189. #define    di_ib        di_ic.ic_ib
  190. #if    defined(NeXT) || defined(MULTIMAX)
  191. #define    di_symlink    di_ic.ic_symlink
  192. #define    di_icflags    di_ic.ic_flags
  193. #endif    defined(NeXT) || defined(MULTIMAX)
  194. #define    di_atime    di_ic.ic_atime
  195. #define    di_mtime    di_ic.ic_mtime
  196. #define    di_ctime    di_ic.ic_ctime
  197. #define    di_rdev        di_ic.ic_db[0]
  198. #define    di_blocks    di_ic.ic_blocks
  199. #define    di_gen        di_ic.ic_gen
  200.  
  201. #ifdef KERNEL
  202. struct inode *inode_list;    /* list of all inodes */
  203.  
  204. extern struct vnodeops ufs_vnodeops;    /* vnode operations for ufs */
  205.  
  206. struct inode    *ialloc();
  207. struct inode    *iget();
  208. ino_t        dirpref();
  209. #endif
  210.  
  211. /* flags */
  212. #define    ILOCKED        0x001        /* inode is locked */
  213. #define    IUPD        0x002        /* file has been modified */
  214. #define    IACC        0x004        /* inode access time to be updated */
  215. #define IMOD        0x008        /* inode has been modified */
  216. #define    IWANT        0x010        /* some process waiting on lock */
  217. #define    ICHG        0x040        /* inode has been changed */
  218. #define    ILWAIT        0x080        /* someone waiting on file lock */
  219. #define IREF        0x100        /* inode is being referenced */
  220. #if    NeXT
  221. #define    IFREE        0x200        /* inode has been free'd */
  222. #define IRELEASE_TO_ZONE 0x8000
  223. #endif    NeXT
  224.  
  225. /* modes */
  226. #define    IFMT        0170000        /* type of file */
  227. #define    IFIFO        0010000        /* named pipe (fifo) */
  228. #define    IFCHR        0020000        /* character special */
  229. #define    IFDIR        0040000        /* directory */
  230. #define    IFBLK        0060000        /* block special */
  231. #define    IFREG        0100000        /* regular */
  232. #define    IFLNK        0120000        /* symbolic link */
  233. #define    IFSOCK        0140000        /* socket */
  234.  
  235. #define    ISUID        04000        /* set user id on execution */
  236. #define    ISGID        02000        /* set group id on execution */
  237. #define    ISVTX        01000        /* save swapped text even after use */
  238. #define    IREAD        0400        /* read, write, execute permissions */
  239. #define    IWRITE        0200
  240. #define    IEXEC        0100
  241.  
  242. #ifdef    KERNEL
  243. /*
  244.  * Convert between inode pointers and vnode pointers
  245.  */
  246. #define VTOI(VP)    ((struct inode *)(VP)->v_data)
  247. #define ITOV(IP)    ((struct vnode *)&(IP)->i_vnode)
  248.  
  249. /*
  250.  * Convert between vnode types and inode formats
  251.  */
  252. extern enum vtype    iftovt_tab[];
  253. extern int        vttoif_tab[];
  254. #define IFTOVT(M)    (iftovt_tab[((M) & IFMT) >> 13])
  255. #define VTTOIF(T)    (vttoif_tab[(int)(T)])
  256.  
  257. #define MAKEIMODE(T, M)    (VTTOIF(T) | (M))
  258.  
  259. /*
  260.  * Lock and unlock inodes.
  261.  */
  262.  
  263. #define    ILOCK(ip) { \
  264.     while ((ip)->i_flag & ILOCKED) { \
  265.         (ip)->i_flag |= IWANT; \
  266.         sleep((caddr_t)(ip), PINOD); \
  267.     } \
  268.     (ip)->i_flag |= ILOCKED; \
  269. }
  270.  
  271. #define    IUNLOCK(ip) { \
  272.     (ip)->i_flag &= ~ILOCKED; \
  273.     if ((ip)->i_flag&IWANT) { \
  274.         (ip)->i_flag &= ~IWANT; \
  275.         wakeup((caddr_t)(ip)); \
  276.     } \
  277. }
  278.  
  279. #define IUPDAT(ip, waitfor) { \
  280.     if (ip->i_flag & (IUPD|IACC|ICHG|IMOD)) \
  281.         iupdat(ip, waitfor); \
  282. }
  283.  
  284. /*
  285.  * Mark an inode with the current (unique) timestamp.
  286.  */
  287. struct timeval iuniqtime;
  288.  
  289. #ifdef NeXT
  290. #define IMARK(ip) { \
  291.     microtime(&iuniqtime); \
  292.     if ((ip)->i_flag & IACC) { \
  293.         (ip)->i_atime = iuniqtime.tv_sec; \
  294.     } \
  295.     if ((ip)->i_flag & IUPD) { \
  296.         (ip)->i_mtime = iuniqtime.tv_sec; \
  297.     } \
  298.     if ((ip)->i_flag & ICHG) { \
  299.         ip->i_diroff = 0; \
  300.         (ip)->i_ctime = iuniqtime.tv_sec; \
  301.     } \
  302. }
  303. #else
  304. #define IMARK(ip) { \
  305.     if (time.tv_sec > iuniqtime.tv_sec || \
  306.         time.tv_usec > iuniqtime.tv_usec) { \
  307.         iuniqtime.tv_sec = time.tv_sec; \
  308.         iuniqtime.tv_usec = time.tv_usec; \
  309.     } else { \
  310.         iuniqtime.tv_usec++; \
  311.     } \
  312.     if ((ip)->i_flag & IACC) { \
  313.         (ip)->i_atime = iuniqtime.tv_sec; \
  314.     } \
  315.     if ((ip)->i_flag & IUPD) { \
  316.         (ip)->i_mtime = iuniqtime.tv_sec; \
  317.     } \
  318.     if ((ip)->i_flag & ICHG) { \
  319.         ip->i_diroff = 0; \
  320.         (ip)->i_ctime = iuniqtime.tv_sec; \
  321.     } \
  322. }
  323. #endif NeXT
  324.  
  325. #define ITIMES(ip) { \
  326.     if ((ip)->i_flag & (IUPD|IACC|ICHG)) { \
  327.         (ip)->i_flag |= IMOD; \
  328.         IMARK(ip); \
  329.         (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
  330.     } \
  331. }
  332.  
  333. #define ESAME    (-1)        /* trying to rename linked files (special) */
  334.  
  335. /*
  336.  *  Macros for modifying inode reference counts - used to check for consistency
  337.  *  at each reference.
  338.  *
  339.  *  The idecr_chk() macro is defined such that it doesn't decrement the
  340.  *  reference count when already zero.  This is in order to avoid the nested
  341.  *  iincr panic which would otherwise occur when update() tries to sync the
  342.  *  inode before halting and increments the count back to zero.
  343.  *
  344.  *  The panic message strings are initialized variables rather than constant
  345.  *  strings since they are potentially used in many places.
  346.  */
  347. extern char *PANICMSG_IINCR;
  348. extern char *PANICMSG_IDECR;
  349.  
  350. #define    iincr_chk(ip)    { if (++((ip)->i_count) == 0) panic(PANICMSG_IINCR); }
  351. #define    idecr_chk(ip)    { if (((ip)->i_count) != 0) ((ip)->i_count--); else panic(PANICMSG_IDECR); }
  352.  
  353. /*
  354.  * Check that file is owned by current user or user is su.
  355.  */
  356. #define OWNER(CR, IP)    (((CR)->cr_uid == (IP)->i_uid)? 0: (suser()? 0: u.u_error))
  357. /*
  358.  * enums
  359.  */
  360. enum de_op    { DE_CREATE, DE_LINK, DE_RENAME };    /* direnter ops */
  361.  
  362. /*
  363.  * This overlays the fid sturcture (see vfs.h)
  364.  */
  365. struct ufid {
  366.     u_short    ufid_len;
  367.     ino_t    ufid_ino;
  368.     long    ufid_gen;
  369. };
  370. #endif    KERNEL
  371.